package org.teachertools.web.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.teachertools.data.Competence;
import org.teachertools.services.CompetenceService;
import org.teachertools.web.forms.CompetenceForm;
import org.teachertools.web.forms.CompetenceFormMapping;

public class CompetenceViewAction extends CommonAction {
    @Override
    protected ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        CompetenceService competenceService = this.getServiceLocator().getCompetenceService();
        Long id = Long.parseLong(request.getParameter("id"));
        Competence competence = competenceService.get(id);
        CompetenceFormMapping.mappingDTOToForm(competence, (CompetenceForm) form);
        ((CompetenceForm) form).setIsUpdate(Boolean.TRUE);

        Long idCategorie = competence.getMatiere().getCategorie().getId();
        request.setAttribute("idCategorie", idCategorie);

        addCategoryList(request);
        addMatiereList(request);

        return mapping.findForward(CONTINUE);
    }
}
